package com.edooteach.tencent.handle.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.demo2do.core.wechat.entity.token.Token;
import com.edooteach.tencent.CacheKeys;
import com.edooteach.tencent.accessor.WechatTokenAccessor;
import com.edooteach.tencent.handle.WechatTokenHandler;

/**
 * 
 * @author mohanlan
 *
 */
@Component("wechatTokenHandler")
public class WechatTokenHandlerImpl implements WechatTokenHandler {
    
    private static final Logger logger = LoggerFactory.getLogger(WechatTokenHandlerImpl.class);
    
    @Autowired
    private WechatTokenAccessor wechatTokenAccessor;
    
    /* (non-Javadoc)
     * @see com.demo2do.wechatmcs.handle.WechatTokenHandler#requestAccessToken()
     */
    @Cacheable(CacheKeys.WechatCache.ACCESS_TOKEN)
    public Token requestAccessToken() {
        
        logger.trace("#requestAccessToken - Request access_token from tencent at {}.", System.currentTimeMillis());
        
        return wechatTokenAccessor.requestAccessToken();
    }

}
